import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/user/login',
    method: 'post',
    data
  })
}

export function mobileLogin(data) {
  return request({
    url: '/mobile/login',
    method: 'post',
    data
  })
}

export function wxLogin() {
  return request({
    url: '/wechat/login',
    method: 'get'
  })
}

export function wxCallback(code,state) {
  return request({
    url: '/wechat/callback?code='+code+'&state='+state,
    method: 'get'
  })
}

export function smsCode(phone) {
  return request({
    url: '/mobile/smsCode?phone='+phone,
    method: 'get'
  })
}

export function getInfo() {
  return request({
    url: '/profile/userinfo',
    method: 'get'
  })
}

export function logout() {
  return request({
    url: '/logout',
    method: 'post'
  })
}

// 条件分页查询用户列表
export function getList(query, current = 1, size = 20) {
  return request({
    url: `/system/user/search`,
    method: 'post',
    data: {...query, current, size}
  })
}

// 新增用户
export function add( data ) {
  return request({
    url: `/system/user`,
    method: 'post',
    data
  })
}

// 查询用户信息
export function getById( id ) {
  return request({
    url: `/system/user/${id}`,
    method: 'get'
  })
}

// 更新
export function update( data ) {
  return request({
    url: `/system/user`,
    method: 'put',
    data
  })
}

// 删除
export function deleteById(id) {
  return request({
    url: `/system/user/${id}`,
    method: 'delete'
  })
}

// 提交修改新密码
export function updatePassword(data) {
  return request({
    url: `/system/user/password`,
    method: 'put',
    data
  })
}
